GtkAllocation *allocation)
{
const GtkWidgetAuxInfo *aux_info;
- GtkRequisition min, natural;
+ gint natural_width;
+ gint natural_height;
int x, y, w, h;
aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
- gtk_widget_get_preferred_size (widget, &min, &natural);
-
- get_span_inside_border_horizontal (widget,
- aux_info,
- allocation->width,
- natural.width,
- &x, &w);
- get_span_inside_border_vertical (widget,
- aux_info,
- allocation->height,
- natural.height,
- &y, &h);
+ if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
+ {
+ gtk_widget_get_preferred_width (widget, NULL, &natural_width);
+ get_span_inside_border_horizontal (widget,
+ aux_info,
+ allocation->width,
+ natural_width,
+ &x, &w);
+
+ gtk_widget_get_preferred_height_for_width (widget, w, NULL, &natural_height);
+ get_span_inside_border_vertical (widget,
+ aux_info,
+ allocation->height,
+ natural_height,
+ &y, &h);
+ }
+ else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
+ {
+ gtk_widget_get_preferred_height (widget, NULL, &natural_height);
+ get_span_inside_border_vertical (widget,
+ aux_info,
+ allocation->height,
+ natural_height,
+ &y, &h);
+
+ gtk_widget_get_preferred_width_for_height (widget, h, NULL, &natural_width);
+ get_span_inside_border_horizontal (widget,
+ aux_info,
+ allocation->width,
+ natural_width,
+ &x, &w);
+ }
allocation->x += x;
allocation->y += y;
gtk_widget_show_all (test_window);
}
+static void
+open_valigned_label_window (void)
+{
+ GtkWidget *window, *box, *label, *frame;
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ g_signal_connect (test_window, "delete-event",
+ G_CALLBACK (gtk_main_quit), test_window);
+
+ box = gtk_vbox_new (FALSE, 0);
+ gtk_widget_show (box);
+ gtk_container_add (GTK_CONTAINER (window), box);
+
+
+ label = gtk_label_new ("Some wrapping text with width-chars = 15 and max-width-chars = 35");
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_label_set_width_chars (GTK_LABEL (label), 15);
+ gtk_label_set_max_width_chars (GTK_LABEL (label), 35);
+
+ gtk_widget_show (label);
+
+ frame = gtk_frame_new (NULL);
+ gtk_widget_show (frame);
+ gtk_container_add (GTK_CONTAINER (frame), label);
+
+ gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
+ gtk_widget_set_halign (frame, GTK_ALIGN_FILL);
+
+ gtk_box_pack_start (GTK_BOX (box), frame, TRUE, TRUE, 0);
+
+ gtk_window_present (GTK_WINDOW (window));
+}
+
int
main (int argc, char *argv[])
{
open_control_window ();
open_alignment_window ();
open_margin_window ();
+ open_valigned_label_window ();
gtk_main ();